package com.lyj.mp.config;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisConfig {

    /**
     * 配置Mybatis-Plus拦截器
     *
     * @return MybatisPlusInterceptor实例，用于配置Mybatis-Plus的各种拦截器
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 创建MybatisPlusInterceptor实例
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 创建PaginationInnerInterceptor实例，用于分页查询
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置最大分页限制，防止查询过多数据
        paginationInnerInterceptor.setMaxLimit(1000L);
        // 将分页拦截器添加到Mybatis-Plus拦截器中
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        // 返回配置好的MybatisPlusInterceptor实例
        return interceptor;
    }
}
